package com.ellricky.excute_president.ui.activity.home.leave

import android.view.View
import com.ellricky.baselib.http.callback.ECallback
import com.ellricky.baselib.ui.base.BaseDetailActivity
import com.ellricky.excute_president.*
import kotlinx.android.synthetic.main.pd_activity_leave_detail.*

class LeaveApplyDetailActivity : BaseDetailActivity() {

    private lateinit var approveStatus: String

    override fun getChildContentLayout(): Int {
        return R.layout.pd_activity_leave_detail
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = getString(R.string.pd_leave_detail)

        approveStatus = intent.getStringExtra(KEY_APPROVE_STATUS) ?: ""
        when (approveStatus) {

            LEAVE_APPLY_NOT_AUDIT -> {
                rlAudit.visibility = View.GONE
                rlDeal.visibility = View.VISIBLE
            }

            LEAVE_APPLY_AGREE,
            LEAVE_APPLY_REFUSE -> {
                rlAudit.visibility = View.VISIBLE
                rlDeal.visibility = View.GONE
            }

            else -> {
                rlAudit.visibility = View.GONE
                rlDeal.visibility = View.GONE
            }

        }


        btnRefuse.setOnClickListener(this)
        btnAgree.setOnClickListener(this)

        loadDetailData(id)

    }


    override fun onClickView(v: View?) {
        super.onClickView(v)
        var approveStatus:String? = null
        when (v) {
            btnRefuse -> approveStatus = LEAVE_APPLY_REFUSE
            btnAgree ->approveStatus = LEAVE_APPLY_AGREE
        }

        approveStatus?.let {
            val paramMap = mutableMapOf<String, Any>(
                    "id" to id,
                    "approveStatus" to approveStatus
            )
            mPresenter.sendBackRequest(API_LEAVE_AUDIT, paramMap)
        }

    }


    private fun loadDetailData(id: String) {
        mPresenter.loadDetail(API_LEAVE_DETAIL, id, object : ECallback<PdLeaveDetailEntity>(this) {
            override fun onSuccess(data: PdLeaveDetailEntity?, msg: String) {

                tvName.text = data?.name
                tvClass.value = data?.className
                tvDate.value = data?.leaveDate
                tvTime.value = data?.leaveTime
                tvType.value = data?.leaveType
                tvReason.text = data?.leaveReason
                tvTempTeacher.value = data?.changeTeacherName

                tvAuditPerson.value = data?.approveName
                tvAuditResult.value = data?.approveStatusName
                tvAuditDate.value = data?.approveDate
            }
        })
    }


}